package com.example.orderflow.controller.flow;

import com.example.orderflow.controller.base.ABaseController;
import com.example.orderflow.entity.vo.ResponseVO;
import com.example.orderflow.service.ApprovalStageService;
import com.example.orderflow.service.ApproveHistoryService;
import com.example.orderflow.service.OrderInfoService;
import com.example.orderflow.service.UserInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;


/**
 * 审核阶段：订单生产
 * 审核等级：6
 */
@RestController
public class OrderProductionController extends ABaseController {

    @Autowired
    UserInfoService userInfoService;

    @Autowired
    ApprovalStageService approvalStageService;

    @Autowired
    ApproveHistoryService approveHistoryService;

    @Autowired
    OrderInfoService orderInfoService;

    /**
     * 订单生产 通过 6
     * @param map
     * orderId 订单编号
     * approveBy 审批人
     * qualityTesting 目标质检
     * @return
     */
    @PostMapping("/orderProductionPass")
    protected <T> ResponseVO orderProductionPass(@RequestBody Map<String,String> map) {

        String orderId = map.get("orderId"); //订单号
        String approveBy = map.get("userName"); //审批人
        String qualityTesting = map.get("qualityTesting"); //

        int levelId = 6;
        String levelIdS = "6";

        //核实订单号和审批人

        //找到下一个等级的名称
        String Nextlevelname = approvalStageService.getApprovalStageByApprovalId(levelId+1).getLevelName();

        //更改单人审核状态
        approveHistoryService.updateDefaultApproveHistoryObjectState(orderId,levelIdS,approveBy,"已通过","1");

        //更改对应的单人审核状态

        //更改订单审核状态
        orderInfoService.updateOrderInfoLevelName(orderId,Nextlevelname);

        //添加新的审核状态
        approveHistoryService.createDefaultApproveHistory(orderId,"7",qualityTesting);

        return getSuccessResponseVO("该订单生产阶段已完成");

    }

}
